<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/WEB-INF/view/common/talent-header.jspf"%> 

	<ul class="nav nav-tabs" role="tablist">
	  <li role="presentation" ><a href="<%=request.getContextPath()%>/CompanyServlet?command=main">审核</a></li>
	  <li role="presentation" class="active"><a href="<%=request.getContextPath()%>/PositionServlet?command=main">职位管理</a></li>
	</ul>

<div style="width:600px;margin:0 auto">
	<table class="table">
		<caption>
			<strong>职位管理：</strong><a
				href="<%=request.getContextPath()%>/PositionServlet?command=toAddUI">发布职位</a>
		</caption>
		<thead>
			<tr>
				<th>编号</th>
				<th>职位名称</th>
				<th>薪资范围</th>
				<th>发布时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${positionList }" var="position" varStatus="v">
				<tr>
					<th scope="row">${v.count }</th>
					<td><a
						href="<%=request.getContextPath()%>/PositionServlet?command=preupdate&id=${position.id}">${position.name }</a></td>
					<td>${position.salary1 }-${position.salary2 }</td>
					<td><fmt:formatDate value="${position.releaseTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
					<td><a href="javascript:void(0)" onclick="del(this,${position.id})">删除</a></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</div>
<%@ include file="/WEB-INF/view/common/footer.jspf"%>
<script>
	/**
	 * AJAX
	 */
	function del(obj,positionId){
		 layer.confirm('确定要删除吗？', {
		    	closeBtn: 0,
		        icon : 3,
		        btn: ['删除','取消'] //按钮
		    }, function(){
		    	// 创建XMLHttpRequest
				var xmlhttp;
				if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}else{// code for IE6, IE5
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				// XMLHttpRequest请求
				xmlhttp.open('GET', '<%=request.getContextPath()%>/PositionServlet?command=delete&id=' + positionId + '&time=' + new Date().getTime(), true);
				xmlhttp.send();
				//添加监听
				xmlhttp.onreadystatechange=function() {
				// XMLHttpRequest响应
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						 var text = xmlhttp.responseText;
						// 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
						    if (text == 'fail') {
						    	layer.msg('操作失败！', {time: 2000, icon: 5});
						    } else {
						    	layer.msg('操作成功！', {time: 2000, icon: 6});
						    	$(obj.parentNode.parentNode).remove();
						    }
					}
				}
		    });
		
	}
	/**
	 * 信息提示框
	 */
	toastr.options = {
	  "closeButton": true,
	  "debug": false,
	  "positionClass": "toast-top-right",
	  "onclick": null,
	  "showDuration": "300",
	  "hideDuration": "1000",
	  "timeOut": "3000",
	  "extendedTimeOut": "1000",
	  "showEasing": "swing",
	  "hideEasing": "linear",
	  "showMethod": "fadeIn",
	  "hideMethod": "fadeOut"
	}
	if ('${success }') {
		toastr.success('${success }');
	}
	if ('${error }') {
		toastr.error('${error }');
	}
	
	/**
	 * 审核
	 */
	 function verify(applicationId) {
	    //询问框
	    layer.confirm('通过还是拒绝？', {
	    	closeBtn: 0,
	        icon : 3,
	        btn: ['通过','拒绝'] //按钮
	    }, function(){
	        layer.msg('您选择了通过！', {icon: 1, time: 1000});
	        location = '<%=request.getContextPath()%>/ApplicationServlet?command=verify&status=2&applicationId=' + applicationId;
	    }, function(){
	        layer.msg('您选择了拒绝！', {icon: 2, time: 1000});
	        location = '<%=request.getContextPath()%>/ApplicationServlet?command=verify&status=3&applicationId=' + applicationId;
	    });
	}
		
	/**
	 * 跳转到指定的页数
	 */
	function goPage(obj) {
		submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerifyByPage&pageNo=' + obj.value);
	}
	
	/**
	 * 分页时，使用JS使用表单
	 */
	function submitForm(url) {
		var conditionForm = document.getElementById('conditionForm');
		conditionForm.action = url;
		conditionForm.submit();
	}
</script>